package com.uam.core.entity.model;


import com.uam.core.entity.constant.CommonConstant;
import com.uam.core.entity.enums.TrackErrorCode;
import com.uam.core.entity.exception.UamServerException;
import lombok.Data;

/**
 * @author heguanglong
 */
@Data
public class GeoPoint {
    public GeoPoint(){

    }

    public GeoPoint(double x, double y){
        this.x=x;
        this.y=y;
    }
    private Double x;
    private Double y;

    public String pointToString(){
        return   this.x+ "," + this.y;
    }

    public void checkInfo() {
        try {
            Double longitude1 = x;
            int y = longitude1.intValue();
            if (y < CommonConstant.MINUS_ONE_HUNDRED_AND_EIGHTY || y >= CommonConstant.ONE_HUNDRED_AND_EIGHTY_ONE) {
                throw new UamServerException(TrackErrorCode.PARAM_ERROR).setAddMessage("经度格式在-180～+180之间");
            }
        } catch (Exception e) {
            throw new UamServerException(TrackErrorCode.PARAM_ERROR).setAddMessage("经度格式不正确");
        }

        try {
            Double latitude1 = y;
            int x = latitude1.intValue();
            if (x < CommonConstant.MINUS__NINETY_ONE || x >= CommonConstant.NINETY_ONE) {
                throw new UamServerException(TrackErrorCode.PARAM_ERROR).setAddMessage("纬度格式在-90～+90之间");
            }
        } catch (Exception e) {
            throw new UamServerException(TrackErrorCode.PARAM_ERROR).setAddMessage("纬度格式不正确");
        }
    }
}
